﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ucb.Workshop.Business;

namespace Ucb.Workshop.WinApp
{
    public partial class Autenticacion : Form
    {
        User _usuario = new User();
        internal User Usuario
        {
            get { return _usuario; }
            set { _usuario = value; }
        }
        public Autenticacion()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            validar();
        }

        public void validar()
        {
            User usuario = new User().GetUsuarioPorAutentificacion(txtLogin.Text.Trim(), txtPassword.Text.Trim());
            if (usuario != null)
            {
                this.Usuario = usuario;
                MainForm p = new MainForm();
                this.Visible = false;
                p.Show();
            }
            else
                lbError.Text = "Los datos son incorrectos!!!";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
            this.Visible = false;
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            MainForm principal = new MainForm();
            principal.Show();
        }

        private void txtLogin_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
                validar();
        }

        private void txtLogin_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
                validar();
        }
    }
}
